package com.tyqx.hashchainbiz.controller.wx;

import com.tyqx.hashchainbean.module.WxSaveFile;
import com.tyqx.hashchainbiz.service.WxSaveFileService;
import hashchainutil.common.Dto;
import hashchainutil.common.DtoUtil;
import hashchainutil.common.EmptyUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * @program: hashchain-spring
 * @description:
 * @author: Mr.Li
 * @create: 2020-10-30 15:03
 **/
@RestController
@RequestMapping("/wx/saveFile")
@CrossOrigin
public class WxSaveFileController {


    @Resource
    private WxSaveFileService wxSaveFileService;

    @RequestMapping(value = "/addWxSaveFile", method = RequestMethod.POST)
    @ResponseBody
    public Dto addWxCompany(@RequestBody WxSaveFile wxSaveFile) throws ParseException {
        String message = "";
        if(EmptyUtils.isNotEmpty(wxSaveFile)){
            int flag = wxSaveFileService.insertWxSaveFile(wxSaveFile);
            if(flag>0){
                message = "添加保存文件名称成功";
            }else{
                message =  "添加保存文件名称失败";
            }
        }else{
            message = "信息为空，添加失败";
        }
        return DtoUtil.returnSuccess(message);
    }

    @RequestMapping(value = "/queryWxSaveFileNameByFileUrl", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryCompanyByOpenId(String fileUrl){
        WxSaveFile wxSaveFile = wxSaveFileService.queryWxSaveFileByFilePath(fileUrl);
        if(EmptyUtils.isNotEmpty(wxSaveFile)){
            return DtoUtil.returnSuccess("查询公司成功",wxSaveFile);
        }else{
            return DtoUtil.returnSuccess("未查询到公司记录");
        }
    }





}
